package com.taotao.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.pojo.TaotaoResult;
import com.taotao.common.pojo.TreeNode;
import com.taotao.common.utils.JsonUtils;
import com.taotao.pojo.TbContentCategory;
import com.taotao.service.IContentCategoryService;

/**
 * 内容分类目录列表
 * 
 * @author Administrator
 *
 */
@Controller
@RequestMapping(value = "/content/category")
public class ContentCategoryController {
	@Autowired
	private IContentCategoryService contentCategoryService;

	/**
	 * 获取分类目录类表
	 * 
	 * @param parentId
	 * @return
	 */
	@RequestMapping(value = "/list")
	@ResponseBody
	public String getContentCategoryList(
			@RequestParam(defaultValue = "0", value = "id") Long parentId) {
		List<TreeNode> treeNodes = this.contentCategoryService
				.getContentCategory(parentId);
		return JsonUtils.objectToJson(treeNodes);
	}

	/**
	 * 添加分类目录节点
	 * 
	 * @param contentCategory
	 * @return
	 */
	@RequestMapping(value = "/create")
	@ResponseBody
	public TaotaoResult createContentCategory(TbContentCategory contentCategory) {
		TaotaoResult taotaoResult = this.contentCategoryService
				.createContentCategory(contentCategory);
		return taotaoResult;
	}

	/**
	 * 删除分类目录节点
	 * 
	 * @param contentCategory
	 * @return
	 */
	@RequestMapping(value = "/delete")
	@ResponseBody
	public TaotaoResult deleteContentCategoryById(Long id, Long parentId) {
		TaotaoResult taotaoResult = this.contentCategoryService
				.deleteContentCategoryById(id);
		System.out.println(parentId);
		return taotaoResult;
	}

	/**
	 * 更新分类目录节点
	 * 
	 * @param contentCategory
	 * @return
	 */
	@RequestMapping(value = "/update")
	@ResponseBody
	public TaotaoResult updateContentCategoryById(Long id, String name) {
		TaotaoResult taotaoResult = this.contentCategoryService
				.renameContentCategoryById(id, name);
		return taotaoResult;
	}
}
